function displayMsg(grid){
	var rows = grid.datagrid("getRows");
	if(rows.length>0){
		grid.datagrid('getPager').pagination({displayMsg:'当前显示从{from}到{to}，共{total}条记录。'});}
	else{
		grid.datagrid('getPager').pagination({displayMsg:'没有记录'});
	}
}

//格式化数值成千分位
function toThousands(num) {
	var result = "";
	var fs = false;
	if (num.substr(0,1) == "-") {
		fs = true;
		num = num.substr(1);
	}
	var xs = "";
	var i = num.indexOf(".");
	if (i >= 0) {
		xs = num.substr(i);
		num = num.substr(0, i);
	}
	
	while (num.length > 3) {
		result = ',' + num.slice(-3) + result;
		num = num.slice(0, num.length - 3);
	}
	if (num) {
		result = num + result;
	}
	if (i >= 0) {
		result = result + xs;
	}
	if (fs) {
		result = "-" + result;
	}
	return result;
}

//格式化数值
function formatNumeric(value, scale) {
	var str = "";
	
	if (typeof(value) != "undefined" && value != null) {
		if (value != 0 && value != 0.00) {
			str = value.toFixed(scale);
			str = toThousands(str);
		}	
	}

	return str;
}

//默认数值格式化(2位小数)
function numeric_formatter(value, rowData, rowIndex) {
	var scale = 2;
	var s = formatNumeric(value, scale);
	return s;
}

//格式化成整数
function numeric_formatter_0(value, rowData, rowIndex) {
	var scale = 0;
	var s = formatNumeric(value, scale);
	return s;
}

//百分数数值格式化(原值乘以100, 保留2位小数)
function numeric_formatter_bl(value, rowData, rowIndex) {
	return formatNumeric_ex(value, 2, 100, false, true, "%");
}

//百分数数值格式化(原值乘以100, 最多保留2位小数,最后加%)
function numeric_formatter_sl_2(value, rowData, rowIndex) {
	return formatNumeric_ex(value, 2, 100, true, true, "%");
}

//数值格式化,可指定小数位数，后缀，按比例，去除小数点后的0，千分位格式
function formatNumeric_ex(value, scale, multipli, removeLastZero, thousands, suffix) {
	var str = "";
	
	if (typeof(value) != "undefined" && value != null) {
		if (value != 0 && value != 0.00) {
			var newValue = value * multipli;
			str = newValue.toFixed(scale);
			if (scale > 0 && removeLastZero) {
				var i = str.indexOf(".");
				if (i >= 0) {
					var num = str.substr(0, i);
					var xs = str.substr(i+1);
					
					var last_index = xs.length;
					for (var j = xs.length - 1; j >= 0; j--) {
						var tmp_char = xs.charAt(j);
						if (tmp_char != "0") {
							break;
						}
						
						last_index--;
					}
					
					if (last_index >= 1) {
						str = num + "." + xs.substring(0, last_index);
					} else {
						str = num;
					}
				}
			}
			if (thousands) {
				str = toThousands(str);
			}
			if (suffix != null && suffix.length > 0) {
				str = str + suffix;
			}
		}	
	}

	return str;
}

//解决EasyUI datagrid 没有数据行时，不显示水平滚动条的问题，
function fix_easyui_datagrid_scroll(table_id) {
	var jq_table = $("#" + table_id);
	
	var jq_fix_div = jq_table.parent().find(".datagrid-view2 > .datagrid-body > .datagrid-body-fixscroll");
	if (jq_fix_div.length > 0) {
		return;
	}
	
	var data = jq_table.datagrid("getData");
	var total = data.total;
	if (total == 0) {
		var width = jq_table.parent().find(".datagrid-view2 > .datagrid-header > .datagrid-header-inner > .datagrid-htable .datagrid-header-row").width();
		var datagrid_btable = jq_table.parent().find(".datagrid-view2 > .datagrid-body > table");
		var str = String.format("<div class='datagrid-body-fixscroll' style='width:{0}px;border:solid 0px;height:1px;'></div>", width);
		datagrid_btable.before(str);
	}
}